using Castle.MonoRail.Framework;

using Tickets.Model;
using Tickets.Model.Repositories;

namespace Tickets.WebUI.Controllers
{

	[Layout("default"), Rescue("generalerror")]
	public class HomeController : SmartDispatcherController
	{
		private IProjectRepository projectRepository;

		public HomeController()
		{
			// Este objeto lo tomo en runtime desde el framework de IoC (Windsor)
			projectRepository = (IProjectRepository)ServiceLocator.Resolve(typeof(IProjectRepository));
		}

		public void Index()
		{
		}

		public void ProjectList()
		{
			PropertyBag["projects"] = projectRepository.GetAll();
		}

		public void ProjectDetail(int id)
		{
			PropertyBag["project"] = projectRepository.GetById(id);
		}

		public void CreateSchemaAndData()
		{
			// Este objeto lo tomo en runtime desde el framework de IoC (Windsor)
			ISchemaUtil schemaUtil = (ISchemaUtil)ServiceLocator.Resolve(typeof(ISchemaUtil));

			schemaUtil.RebuildSchema();
			schemaUtil.LoadTestData();

			Flash["alert"] = "Database and data created succesfully";
			RedirectToAction("index");
		}
	}
}